package server

import "fmt"

var (
	SystemException         = NewException(10000, "系统内部错误")
	NeedLoginException      = NewException(10002, "需要登录")
	InvalidOptException     = NewException(10008, "非法操作")
	GameNotFoundException   = NewException(10005, "房间不存在")
	ArgsException           = NewException(10001, "参数错误")
	CostDeficiencyException = NewException(10013, "玉令不足")
)

type Exception interface {
	Code() int
	Msg() string
	String() string
}

type CommonException struct {
	code int
	msg  string
}

func (ce *CommonException) Code() int {
	return ce.code
}

func (ce *CommonException) Msg() string {
	return ce.msg
}

func (ce *CommonException) String() string {
	return fmt.Sprintf("[%d] %s\n", ce.code, ce.msg)
}

func NewException(code int, msg string) Exception {
	return &CommonException{
		code: code,
		msg:  msg,
	}
}
